class _LazyMan {
  constructor(name) {
    let task = () => {
      console.log(`Hi! This is ${name}`);
      this.next()
    }
    this.taskQueue = []
    this.taskQueue.push(task)
    setTimeout(() => {
      this.next()
    }, 0)
  }
  next() {
    let task = this.taskQueue.shift()
    task && task()
  }
  eat(food) {
    let task = () => {
      console.log(`Eat ${food}`);
      this.next()
    }
    this.taskQueue.push(task)
    return this
  }
  sleep(time) {
    let task = () => {
      setTimeout(() => {
        console.log(`Wake up after ${time}`);
        this.next()
      }, time * 1000)
    }
    this.taskQueue.push(task)
    return this
  }
  sleepFirst(time) {
    let task = () => {
      setTimeout(() => {
        console.log(`Wake up after ${time}`);
        this.next()
      }, time * 1000)
    }
    this.taskQueue.unshift(task)
    return this
  }
}
function LazyMan(name) {
  return new _LazyMan(name)
}
LazyMan("Hank").eat("supper").sleepFirst(5)